/**
 * Created by Administrator on 2017/3/2 0002.
 */
var Page2={
    create:function () {
        var page={};

        var tw_t0,tw_t1,tw_gp0,tw_gp1;
        var star0,star1,star2,star3;
        page.ui=new PIXI.DisplayObjectContainer();

        var bg=new PIXI.Sprite(resource['assets/images/p2_bg.png'].texture);
        page.ui.addChild(bg);

        var t0=new PIXI.Sprite(resource['assets/images/p2_t0.png'].texture);
        t0.x=370;
        t0.y=985;
        t0.alpha=0;
        t0.anchor.set(0.5);
        page.ui.addChild(t0);

        var t1=new PIXI.Sprite(resource['assets/images/p0_t1.png'].texture);
        t1.x=370;
        t1.y=1055;
        t1.alpha=0;
        t1.anchor.set(0.5);
        page.ui.addChild(t1);

        var i0=new PIXI.Sprite(resource['assets/images/p2_i0.png'].texture);
        i0.interactive=true;
        i0.name='i0';
        i0.x=253;
        i0.y=341;
        i0.alpha=0;
        i0.anchor.set(0.5);
        page.ui.addChild(i0);
        TweenMax.to(i0,1.5,{y:341-10,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        i0.on('pointerdown',downHandler);
        i0.on('pointerup',upHandler);

        var i1=new PIXI.Sprite(resource['assets/images/p2_i1.png'].texture);
        i1.interactive=true;
        i1.name='i1';
        i1.x=560;
        i1.y=343;
        i1.alpha=0;
        i1.anchor.set(0.5);
        page.ui.addChild(i1);
        TweenMax.to(i1,4,{y:343+15,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        i1.on('pointerdown',downHandler);
        i1.on('pointerup',upHandler);

        var i2=new PIXI.Sprite(resource['assets/images/p2_i2.png'].texture);
        i2.interactive=true;
        i2.name='i2';
        i2.x=685;
        i2.y=384;
        i2.alpha=0;
        i2.anchor.set(0.5);
        page.ui.addChild(i2);
        TweenMax.to(i2,2.5,{y:384-20,rotation:10*Math.PI/180,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        i2.on('pointerdown',downHandler);
        i2.on('pointerup',upHandler);

        var i3=new PIXI.Sprite(resource['assets/images/p2_i3.png'].texture);
        i3.interactive=true;
        i3.name='i3';
        i3.x=330;
        i3.y=715;
        i3.alpha=0;
        i3.anchor.set(0.5);
        page.ui.addChild(i3);

        TweenMax.to(i3,4,{y:715+15,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        TweenMax.to(i3.skew,3,{x:0.07,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        i3.on('pointerdown',downHandler);
        i3.on('pointerup',upHandler);

        var star0= new PIXI.Sprite(resource['assets/images/star.png'].texture);
        star0.x = 75;
        star0.y = 0;
        star0.alpha = 1;
        star0.scale.x=star0.scale.y = 1;
        star0.anchor.set(0.5);
        i0.addChild(star0);
        TweenMax.to(star0,1.5,{alpha:0.5,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        // TweenMax.to(star0,3,{rotation:360*Math.PI/180,repeat:-1});
        TweenMax.to(star0.scale,1.5,{x:0.3,y:0.3,ease:Cubic.easeInOut,yoyo:true,repeat:-1});

        var star1= new PIXI.Sprite(resource['assets/images/star.png'].texture);
        star1.x = -44;
        star1.y = 0;
        star1.alpha = 0.5;
        star1.anchor.set(0.5);
        star1.scale.x=star1.scale.y = 1;
        i1.addChild(star1);
        TweenMax.to(star1,1.5,{delay:1,alpha:1,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        // TweenMax.to(star0,4,{rotation:360*Math.PI/180,repeat:-1});
        TweenMax.to(star1.scale,1.5,{x:0.5,y:0.5,ease:Cubic.easeInOut,yoyo:true,repeat:-1});

        var star2= new PIXI.Sprite(resource['assets/images/star.png'].texture);
        star2.x = 12;
        star2.y = 44;
        star2.alpha = 0.7;
        star2.scale.x=star2.scale.y=0.8;
        star2.anchor.set(0.5);
        i2.addChild(star2);
        TweenMax.to(star2,2.5,{alpha:1,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        // TweenMax.to(star2,2.5,{rotation:360*Math.PI/180,repeat:-1});
        TweenMax.to(star2.scale,2.5,{x:0.3,y:0.3,ease:Cubic.easeInOut,yoyo:true,repeat:-1});

        var star3= new PIXI.Sprite(resource['assets/images/star.png'].texture);
        star3.x = 143;
        star3.y = -111;
        star3.alpha = 0.8;
        star3.anchor.set(0.5);
        i3.addChild(star3);
        TweenMax.to(star3,2,{alpha:1,ease:Cubic.easeInOut,yoyo:true,repeat:-1});
        // TweenMax.to(star3,5,{rotation:-360*Math.PI/180,repeat:-1});
        TweenMax.to(star3.scale,2,{x:0.4,y:0.4,ease:Cubic.easeInOut,yoyo:true,repeat:-1});

        var tip= new PIXI.Sprite(resource['assets/images/tip.png'].texture);
        tip.x = 370;
        tip.y = 1105;
        tip.alpha = 1;
        tip.anchor.set(0.5);
        page.ui.addChild(tip);
        TweenMax.to(tip,0.7,{y:1105-20,ease:Cubic.easeInOut,yoyo:true,repeat:-1});

        var arr_texture=[];
        for(var i=1;i<25;i++)
        {
            if(i<10)
            {
                var texture = resource['assets/images/click000'+i.toString()+'.png'].texture;
            }
            else
            {
                var texture = resource['assets/images/click00'+i.toString()+'.png'].texture;
            }
            arr_texture.push(texture);

        }
        var sp_click=new PIXI.extras.AnimatedSprite(arr_texture);
        sp_click.anchor.set(0.5);
        sp_click.x=252;
        sp_click.y=366;
        sp_click.animationSpeed=0.3;
        sp_click.alpha=0;
        sp_click.gotoAndPlay(1);
        page.ui.addChild(sp_click);

        var sp_click1=new PIXI.extras.AnimatedSprite(arr_texture);
        sp_click1.anchor.set(0.5);
        sp_click1.x=563;
        sp_click1.y=281;
        sp_click1.animationSpeed=0.3;
        sp_click1.alpha=0;
        sp_click1.gotoAndPlay(1);
        page.ui.addChild(sp_click1);

        var sp_click2=new PIXI.extras.AnimatedSprite(arr_texture);
        sp_click2.anchor.set(0.5);
        sp_click2.x=634;
        sp_click2.y=477;
        sp_click2.animationSpeed=0.3;
        sp_click2.alpha=0;
        sp_click2.gotoAndPlay(1);
        page.ui.addChild(sp_click2);

        var sp_click3=new PIXI.extras.AnimatedSprite(arr_texture);
        sp_click3.anchor.set(0.5);
        sp_click3.x=269;
        sp_click3.y=643;
        sp_click3.animationSpeed=0.3;
        sp_click3.alpha=0;
        sp_click3.gotoAndPlay(1);
        page.ui.addChild(sp_click3);
        // page.ui.addChild(sp_click);
        // tw_click=new TWEEN.Tween({alpha:0,scale:0})
        //     .to({alpha:1,scale:1},1000)
        //     .onUpdate(function () {
        //         sp_click.scale.x=this.scale;
        //         sp_click.scale.y=this.scale;
        //         sp_click.alpha=this.alpha;
        //     })
        //     .delay(300)
        //     .easing(TWEEN.Easing.Back.Out)

        page.ui.interactive=true;
        page.ui.on('pointermove',moveHandler);
        // var arr_texture=[];
        // for(var i=1;i<25;i++)
        // {
        //     if(i<10)
        //     {
        //         var texture = resource['assets/images/click000'+i.toString()+'.png'].texture;
        //     }
        //     else
        //     {
        //         var texture = resource['assets/images/click00'+i.toString()+'.png'].texture;
        //     }
        //     arr_texture.push(texture);
        //
        // }
        // var sp_click=new PIXI.extras.AnimatedSprite(arr_texture);
        // sp_click.anchor.set(0.5);
        // sp_click.x=380;
        // sp_click.y=900;
        // sp_click.animationSpeed=0.4;
        // sp_click.alpha=0;
        // sp_click.gotoAndPlay(1);
        // // page.ui.addChild(sp_click);
        // tw_click=new TWEEN.Tween({alpha:0,scale:0})
        //     .to({alpha:1,scale:1},1000)
        //     .onUpdate(function () {
        //         sp_click.scale.x=this.scale;
        //         sp_click.scale.y=this.scale;
        //         sp_click.alpha=this.alpha;
        //     })
        //     .delay(300)
        //     .easing(TWEEN.Easing.Back.Out);
        var bool;
        var bool_down;
        var mouseD=0;
        function moveHandler(e)
        {
            if(bool_down)
            {
                if(Math.abs(e.data.global.y-mouseD)>3)
                {
                    bool=false;
                }
            }
        }
        function upHandler(e)
        {
            if(bool)
            {
                bool=false;
                bool_down=false;
                var event = new CustomEvent("Game_SubPageIn", {detail:e.currentTarget.name });
                document.dispatchEvent(event);
            }
        }
        function downHandler(e)
        {
            bool_down=true;
            bool=true;
            console.log(e.currentTarget.name);
            // console.log(e.data.)
            mouseD=e.data.global.y;

        }




        page.In=function () {
            TweenMax.killTweensOf(t0);
            TweenMax.killTweensOf(t1);
            TweenMax.killTweensOf(t1);

            t0.x=370+100;
            t1.x=370-100;
            tw_t0=TweenMax.to(t0,1,{delay:0.5,x:370,alpha:1,ease:Cubic.easeInOut});
            tw_t1=TweenMax.to(t1,1,{delay:0.5,x:370,alpha:1,ease:Cubic.easeInOut});

            tw_i0=TweenMax.to(i0,1,{delay:0.0,alpha:1,ease:Cubic.easeInOut});
            tw_i1=TweenMax.to(i1,1,{delay:0.2,alpha:1,ease:Cubic.easeInOut});
            tw_i2=TweenMax.to(i2,1,{delay:0.4,alpha:1,ease:Cubic.easeInOut});
            tw_i3=TweenMax.to(i3,1,{delay:0.6,alpha:1,ease:Cubic.easeInOut});

            sp_click.alpha=sp_click1.alpha=sp_click2.alpha=sp_click3.alpha=0;
            TweenMax.to(sp_click,1,{delay:0.0,alpha:0.7,ease:Cubic.easeInOut});
            TweenMax.to(sp_click1,1,{delay:0.2,alpha:0.7,ease:Cubic.easeInOut});
            TweenMax.to(sp_click2,1,{delay:0.4,alpha:0.7,ease:Cubic.easeInOut});
            TweenMax.to(sp_click3,1,{delay:0.6,alpha:0.7,ease:Cubic.easeInOut});
        }

        page.Out=function () {
            tw_whole=TweenMax.to(page.ui,0.6,{alpha:0,onComplete:function () {
                t0.alpha=0;
                t1.alpha=0;
                sp_click.alpha=sp_click1.alpha=sp_click2.alpha=sp_click3.alpha=0;
                page.ui.alpha=1;
            }})
        }

        return page;
    }
}